package com.losrebellos.utils.text{	/**	 * @author los rebellos - ben@benoitvinay.com	 */	public final class StringUtils	{		////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// REPLACE
		////////////////////////////////////////////////////////////////////////////////////////////////////////////////		public static function replace(txt:String, search:String, replace:String, flags:String = "gi"):String		{			return txt.replace(new RegExp("\(" + search + ")", flags), replace);		}		// remplace in a string all the array of elements by an element		// useful to clean an url		public static function multipleReplace(txt:String, tabSearch:Array, tabReplace:Array, flags:String = "gi"):String		{			var result:String = txt;						for(var i:Number = 0; i<tabSearch.length; i++)			{				result = replace(result, tabSearch[i], tabReplace[i], flags);			}			return result;		}						////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// SPACE
		////////////////////////////////////////////////////////////////////////////////////////////////////////////////		public static function clean(txt:String):String		{			return replace(txt, " ", "");		}		public static function removeSpace(txt:String):String		{			return txt.replace(RegExUtils.SPACE, "");		}						////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// VALIDATION
		////////////////////////////////////////////////////////////////////////////////////////////////////////////////		public static function isEmail(txt:String):Boolean		{			return RegExUtils.execute(txt, RegExUtils.EMAIL, "i");		}		public static function isPhoneNumber(country:String, txt:String):Boolean		{			return RegExUtils.execute(txt, "^(((\\+" + country + "\\s?\\d{4}|\\(?0\\d{4}\\)?)\\s?\\d{3}\\s?\\d{3})|((\\+" + country + "\\s?\\d{3}|\\(?0\\d{3}\\)?)\\s?\\d{3}\\s?\\d{4})|((\\+" + country + "\\s?\\d{2}|\\(?0\\d{2}\\)?)\\s?\\d{4}\\s?\\d{4}))(\\s?\\#(\\d{4}|\\d{3}))?$");		}		public static function isIntNotNull(txt:String):Boolean		{			return !(int(txt) == 0);		}						////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// GENERATE RANDOM STRING
		////////////////////////////////////////////////////////////////////////////////////////////////////////////////		public static const ALPHABET:String			= "abcdefghijklmnopqrstuvwxyz";		public static const ALPHABET_CAPS:String	= ALPHABET.toUpperCase();		public static const NUMERIC:String			= "0123456789";		public static const EXTRA:String			= "_-";		public static const ALL_CHARACTERS:String	= ALPHABET + NUMERIC + EXTRA;		public static function generateRandomString(length:uint = 10, sets:Array = null):String		{			var characters:String = (sets ? sets.join("") : ALPHABET);			var alphabet:Array = characters.split("");			var alphabetLength:int = alphabet.length;			var randomLetters:String = "";			for(var i:uint = 0; i < length; i++)			{				randomLetters += alphabet[int(Math.floor(Math.random() * alphabetLength))];			}			return randomLetters;		}	}}